﻿using System;
using System.Data.SqlClient;
using Co9320.NamaAlert.Server.Parameters;

namespace Co9320.NamaAlert.Server.BackEnd
{
	internal class DeleteProcess : ProcessObject
	{
		private static int MaxTransaction = Co9320.NamaAlert.Server.Properties.Settings.Default.MaxTransactionOfDelete;

		private AddDeleteParamerter Parameter_;
		private SqlParameter tag;

		public DeleteProcess(AddDeleteParamerter Parameter)
			: base(Parameter)
		{
			if (Parameter.TagValue == null)
			{
				throw new ArgumentException();
			}

			this.Parameter_ = Parameter;

			ProcessObject.TrimValue(Parameter_.TagValue, MaxTransaction);

			base.cmd.CommandText = "EXECUTE dbo.DeleteTag @sid,@cstr,@tag;";
			tag = new SqlParameter("@tag", System.Data.SqlDbType.NVarChar);
			cmd.Parameters.Add(tag);
		}

		public override void DoProcess()
		{
			foreach (string elem in Parameter_.TagValue)
			{
				if (elem.Length < ProcessObject.MaxCharacterLength)
				{
					this.tag.Value = elem;
					cmd.ExecuteNonQuery();
				}
			}

			base.Dispose(true);
		}
	}
}